package com.ch04.ex37;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * Created by zc on 2016/2/18.
 */
public class UserValidator {
    private String name;

    public UserValidator(String name) {
        this.name = name;
    }

    public boolean validate(String name, String passwd){
        Random random = new Random();
        long duartion = (long) (Math.random()*10);
        System.out.printf("Validator %s: Validating a user during %d seconds\n",
                name, duartion);
        try {
            TimeUnit.SECONDS.sleep(duartion);
        } catch (InterruptedException e) {
//            e.printStackTrace();
            return false;
        }

        return random.nextBoolean();
    }

    public String getName() {
        return name;
    }
}
